home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_09_08 / 9n08092a < prev    next >
Text File  |  1991-06-20  |  1KB  |  40 lines

  1.  
  2. /* Read an encoded scan line (all color planes) from a          */
  3. /* PCX-format image file and write the decoded data to a scan   */
  4. /* line buffer                                                  */
  5.  
  6. void pcx_read_line
  7. (
  8.   unsigned char *linep, /* PCX scan line buffer pointer         */
  9.   FILE *fp,             /* PCX image file pointer               */
  10.   int bpline            /* # bytes per line (all color planes)  */
  11. )
  12. {
  13.   int data;         /* Image data byte                          */
  14.   int count;        /* Image data byte repeat count             */
  15.   int offset = 0;   /* Scan line buffer offset                  */
  16.  
  17.   while (offset < bpline)   /* Decode scan line                 */
  18.   {
  19.     data = getc(fp);        /* Get next byte                    */
  20.  
  21.     /* If top two bits of byte are set, lower six bits show how */
  22.     /* many times to duplicate next byte                        */
  23.  
  24.     if ((data & 0xc0) == 0xc0)
  25.     {
  26.       count = data & 0x3f;          /* Mask off repeat count    */
  27.       data = getc(fp);              /* Get next byte            */
  28.       memset(linep, data, count);   /* Duplicate byte           */
  29.       linep += count;
  30.       offset += count;
  31.     }
  32.     else
  33.     {
  34.       *linep++ = (unsigned char) data;  /* Copy byte            */
  35.       offset++;
  36.     }
  37.   }
  38. }
  39.  
  40.